﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Linq;
using NUnit.Framework;
using System.ServiceModel.Syndication;

namespace RssProxyService.Test.Integration
{
    [TestFixture]
    public class FlickerRssMapperTests
    {
        SyndicationItem syndicationItem;
        FlickerRssMapper mapper;

        [SetUp]
        public void Setup()
        {
            mapper = new FlickerRssMapper();

            syndicationItem = new SyndicationItem();
            syndicationItem.Title = new TextSyndicationContent("Title");
            syndicationItem.PublishDate = new DateTimeOffset(new DateTime(2012, 1, 18, 18, 59, 32));
            syndicationItem.LastUpdatedTime = new DateTimeOffset(new DateTime(2012, 1, 18, 19, 30, 15));
            syndicationItem.Links.Add(
                    new SyndicationLink(new Uri("http://imageworld/2.jpg"))
                    {
                        RelationshipType = "enclosure",
                    }
                );
        }

        [Test]
        public void MapSingleArticle_TitleIsPresent_TitleIsMappedProperly()
        {
            var article = mapper.MapSingleArticle(syndicationItem);

            Assert.AreEqual("Title", article.Title);
        }

        [Test]
        public void MapSingleArticle_PublishDateIsPresent_PublishDateIsMappedProperly()
        {
            var article = mapper.MapSingleArticle(syndicationItem);

            Assert.AreEqual(new DateTime(2012, 1, 18, 18, 59, 32), article.PublishDate);
        }

        [Test]
        public void MapSingleArticle_LastUpdatedTimeIsPresent_LastUpdatedTimeIsMappedProperly()
        {
            var article = mapper.MapSingleArticle(syndicationItem);

            Assert.AreEqual(new DateTime(2012, 1, 18, 19, 30, 15), article.UpdateDate);
        }

        [Test]
        public void MapSingleArticle_ImageIsPresent_ImageItemIsPresent()
        {
            var article = mapper.MapSingleArticle(syndicationItem);

            var imageItem = article.Items.FirstOrDefault(item => item.Type == "image");
            Assert.NotNull(imageItem);
        }
    }
}
